package com.walker.elk.netty.protobuf.client;


import com.walker.elk.netty.protobuf.DataObject;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;

public class ProtoBufClientChannelInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel channel) throws Exception {
		
		ChannelPipeline channelPipeline = channel.pipeline();
		
		channelPipeline.addLast(new ProtobufVarint32FrameDecoder());
		
		channelPipeline.addLast(new ProtobufDecoder(DataObject.Person.getDefaultInstance()));
		
		channelPipeline.addLast(new ProtobufVarint32LengthFieldPrepender());
		
		channelPipeline.addLast(new ProtobufEncoder());
		
		channelPipeline.addLast(new ProtoBufClientChannelHandler());
	}

}
